1
|
|
|
/** |
2
|
|
|
* Simple Machines Forum (SMF) |
3
|
|
|
* |
4
|
|
|
* @package SMF |
5
|
|
|
* @author Simple Machines http://www.simplemachines.org |
6
|
|
|
* @copyright 2017 Simple Machines and individual contributors |
7
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
8
|
|
|
* |
9
|
|
|
* @version 2.1 Beta 3 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
(function ($) { |
13
|
|
|
var extensionMethods = { |
14
|
|
|
InsertText: function (text, bClear) { |
15
|
|
|
var bIsSource = this.inSourceMode(); |
16
|
|
|
|
17
|
|
|
// @TODO make it put the quote close to the current selection |
18
|
|
|
|
19
|
|
|
if (!bIsSource) |
20
|
|
|
this.toggleSourceMode(); |
|
|
|
|
21
|
|
|
|
22
|
|
|
var current_value = bClear ? text : this.getSourceEditorValue(false) + text; |
23
|
|
|
this.setSourceEditorValue(current_value); |
24
|
|
|
|
25
|
|
|
if (!bIsSource) |
26
|
|
|
this.toggleSourceMode(); |
|
|
|
|
27
|
|
|
|
28
|
|
|
}, |
29
|
|
|
getText: function (filter) { |
30
|
|
|
var current_value = ''; |
31
|
|
|
|
32
|
|
|
if (this.inSourceMode()) |
33
|
|
|
current_value = this.getSourceEditorValue(false); |
|
|
|
|
34
|
|
|
else |
35
|
|
|
current_value = this.getWysiwygEditorValue(filter); |
36
|
|
|
|
37
|
|
|
return current_value; |
38
|
|
|
}, |
39
|
|
|
appendEmoticon: function (code, emoticon) { |
40
|
|
|
if (emoticon == '') |
41
|
|
|
line.append($('<br>')); |
|
|
|
|
42
|
|
|
else |
43
|
|
|
line.append($('<img>') |
44
|
|
|
.attr({ |
45
|
|
|
src: emoticon, |
46
|
|
|
alt: code, |
47
|
|
|
}) |
48
|
|
|
.click(function (e) { |
49
|
|
|
var start = '', end = ''; |
50
|
|
|
|
51
|
|
|
if (base.opts.emoticonsCompat) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
start = '<span> '; |
54
|
|
|
end = ' </span>'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (base.inSourceMode()) |
58
|
|
|
base.sourceEditorInsertText(' ' + $(this).attr('alt') + ' '); |
|
|
|
|
59
|
|
|
else |
60
|
|
|
base.wysiwygEditorInsertHtml(start + '<img src="' + $(this).attr("src") + '" data-sceditor-emoticon="' + $(this).attr('alt') + '">' + end); |
61
|
|
|
|
62
|
|
|
e.preventDefault(); |
63
|
|
|
}) |
64
|
|
|
); |
65
|
|
|
}, |
66
|
|
|
createPermanentDropDown: function () { |
67
|
|
|
var emoticons = $.extend({}, this.opts.emoticons.dropdown); |
68
|
|
|
var popup_exists = false; |
69
|
|
|
content = $('<div class="sceditor-insertemoticon">'); |
|
|
|
|
70
|
|
|
line = $('<div>'); |
|
|
|
|
71
|
|
|
base = this; |
|
|
|
|
72
|
|
|
|
73
|
|
|
for (smiley_popup in this.opts.emoticons.popup) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
popup_exists = true; |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
if (popup_exists) |
79
|
|
|
{ |
80
|
|
|
base.opts.emoticons.more = base.opts.emoticons.popup; |
81
|
|
|
moreButton = $('<div class="sceditor-more-button sceditor-more button">').text(this._('More')).click(function () { |
|
|
|
|
82
|
|
|
if ($(".sceditor-smileyPopup").length > 0) |
83
|
|
|
{ |
84
|
|
|
$(".sceditor-smileyPopup").fadeIn('fast'); |
85
|
|
|
} |
86
|
|
|
else |
87
|
|
|
{ |
88
|
|
|
var emoticons = $.extend({}, base.opts.emoticons.popup); |
89
|
|
|
var popup_position; |
|
|
|
|
90
|
|
|
var titlebar = $('<div class="catbg sceditor-popup-grip"/>'); |
91
|
|
|
popupContent = $('<div id="sceditor-popup"/>'); |
|
|
|
|
92
|
|
|
allowHide = true; |
|
|
|
|
93
|
|
|
line = $('<div id="sceditor-popup-smiley"/>'); |
|
|
|
|
94
|
|
|
adjheight = 0; |
|
|
|
|
95
|
|
|
|
96
|
|
|
popupContent.append(titlebar); |
97
|
|
|
closeButton = $('<span class="button">').text(base._('Close')).click(function () { |
|
|
|
|
98
|
|
|
$(".sceditor-smileyPopup").fadeOut('fast'); |
99
|
|
|
}); |
100
|
|
|
|
101
|
|
|
$.each(emoticons, base.appendEmoticon); |
102
|
|
|
|
103
|
|
|
if (line.children().length > 0) |
104
|
|
|
popupContent.append(line); |
|
|
|
|
105
|
|
|
if (typeof closeButton !== "undefined") |
106
|
|
|
popupContent.append(closeButton); |
|
|
|
|
107
|
|
|
|
108
|
|
|
// IE needs unselectable attr to stop it from unselecting the text in the editor. |
109
|
|
|
// The editor can cope if IE does unselect the text it's just not nice. |
110
|
|
|
if (base.ieUnselectable !== false) { |
111
|
|
|
content = $(content); |
|
|
|
|
112
|
|
|
content.find(':not(input,textarea)').filter(function () { return this.nodeType===1; }).attr('unselectable', 'on'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
dropdownIgnoreLastClick = true; |
|
|
|
|
116
|
|
|
adjheight = closeButton.height() + titlebar.height(); |
|
|
|
|
117
|
|
|
$dropdown = $('<div class="centerbox sceditor-smileyPopup">') |
|
|
|
|
118
|
|
|
.append(popupContent) |
119
|
|
|
.appendTo($('.sceditor-container')); |
120
|
|
|
|
121
|
|
|
$('.sceditor-smileyPopup').animaDrag({ |
122
|
|
|
speed: 150, |
123
|
|
|
interval: 120, |
124
|
|
|
during: function (e) { |
|
|
|
|
125
|
|
|
$(this).height(this.startheight); |
126
|
|
|
$(this).width(this.startwidth); |
127
|
|
|
}, |
128
|
|
|
before: function (e) { |
|
|
|
|
129
|
|
|
this.startheight = $(this).innerHeight(); |
130
|
|
|
this.startwidth = $(this).innerWidth(); |
131
|
|
|
}, |
132
|
|
|
grip: '.sceditor-popup-grip' |
133
|
|
|
}); |
134
|
|
|
// stop clicks within the dropdown from being handled |
135
|
|
|
$dropdown.click(function (e) { |
136
|
|
|
e.stopPropagation(); |
137
|
|
|
}); |
138
|
|
|
} |
139
|
|
|
}); |
140
|
|
|
} |
141
|
|
|
$.each(emoticons, base.appendEmoticon); |
142
|
|
|
if (line.children().length > 0) |
143
|
|
|
content.append(line); |
|
|
|
|
144
|
|
|
$(".sceditor-toolbar").append(content); |
145
|
|
|
if (typeof moreButton !== "undefined") |
|
|
|
|
146
|
|
|
content.append($('<center/>').append(moreButton)); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
}; |
149
|
|
|
|
150
|
|
|
$.extend(true, $['sceditor'].prototype, extensionMethods); |
151
|
|
|
})(jQuery); |
152
|
|
|
|
153
|
|
|
$.sceditor.command.set( |
154
|
|
|
'pre', { |
155
|
|
|
tooltip: 'Pre', |
156
|
|
|
txtExec: ["[pre]", "[/pre]"], |
157
|
|
|
exec: function () { |
158
|
|
|
this.wysiwygEditorInsertHtml('<pre>', '</pre>'); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
); |
162
|
|
|
$.sceditor.command.set( |
163
|
|
|
'email', { |
164
|
|
|
txtExec: function (caller, selected) { |
165
|
|
|
var display = selected && selected.indexOf('@') > -1 ? null : selected, |
166
|
|
|
email = prompt(this._("Enter the e-mail address:"), (display ? '' : selected)); |
167
|
|
|
if (email) |
168
|
|
|
{ |
169
|
|
|
var text = prompt(this._("Enter the displayed text:"), display || email) || email; |
170
|
|
|
this.insertText("[email=" + email + "]" + text + "[/email]"); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
); |
175
|
|
|
$.sceditor.command.set( |
176
|
|
|
'link', { |
177
|
|
|
txtExec: function (caller, selected) { |
178
|
|
|
var display = selected && selected.indexOf('http://') > -1 ? null : selected, |
179
|
|
|
url = prompt(this._("Enter URL:"), (display ? 'http://' : selected)); |
180
|
|
|
if (url) |
181
|
|
|
{ |
182
|
|
|
var text = prompt(this._("Enter the displayed text:"), display || url) || url; |
183
|
|
|
this.insertText("[url=\"" + url + "\"]" + text + "[/url]"); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$.sceditor.command.set( |
190
|
|
|
'bulletlist', { |
191
|
|
|
txtExec: function (caller, selected) { |
192
|
|
|
if (selected) |
193
|
|
|
{ |
194
|
|
|
var content = ''; |
195
|
|
|
|
196
|
|
|
$.each(selected.split(/\r?\n/), function () { |
197
|
|
|
content += (content ? '\n' : '') + '[li]' + this + '[/li]'; |
198
|
|
|
}); |
199
|
|
|
|
200
|
|
|
this.insertText('[list]\n' + content + '\n[/list]'); |
201
|
|
|
} |
202
|
|
|
else |
203
|
|
|
this.insertText('[list]\n[li]', '[/li]\n[li][/li]\n[/list]'); |
|
|
|
|
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$.sceditor.command.set( |
209
|
|
|
'orderedlist', { |
210
|
|
|
txtExec: function (caller, selected) { |
211
|
|
|
if (selected) |
212
|
|
|
{ |
213
|
|
|
var content = ''; |
214
|
|
|
|
215
|
|
|
$.each(selected.split(/\r?\n/), function () { |
216
|
|
|
content += (content ? '\n' : '') + '[li]' + this + '[/li]'; |
217
|
|
|
}); |
218
|
|
|
|
219
|
|
|
this.insertText('[list type=decimal]\n' + content + '\n[/list]'); |
220
|
|
|
} |
221
|
|
|
else |
222
|
|
|
this.insertText('[list type=decimal]\n[li]', '[/li]\n[li][/li]\n[/list]'); |
|
|
|
|
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
); |
226
|
|
|
|
227
|
|
|
$.sceditor.command.set( |
228
|
|
|
'table', { |
229
|
|
|
txtExec: ["[table]\n[tr]\n[td]", "[/td]\n[/tr]\n[/table]"] |
230
|
|
|
} |
231
|
|
|
); |
232
|
|
|
|
233
|
|
|
$.sceditor.command.set( |
234
|
|
|
'floatleft', { |
235
|
|
|
tooltip: 'Float left', |
236
|
|
|
txtExec: ["[float=left max=45%]", "[/float]"], |
237
|
|
|
exec: function () { |
238
|
|
|
this.wysiwygEditorInsertHtml('<div class="floatleft">', '</div>'); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
); |
242
|
|
|
|
243
|
|
|
$.sceditor.command.set( |
244
|
|
|
'floatright', { |
245
|
|
|
tooltip: 'Float right', |
246
|
|
|
txtExec: ["[float=right max=45%]", "[/float]"], |
247
|
|
|
exec: function () { |
248
|
|
|
this.wysiwygEditorInsertHtml('<div class="floatright">', '</div>'); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
); |
252
|
|
|
|
253
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
254
|
|
|
'abbr', { |
255
|
|
|
tags: { |
256
|
|
|
abbr: { |
257
|
|
|
title: null |
258
|
|
|
} |
259
|
|
|
}, |
260
|
|
|
format: function (element, content) { |
261
|
|
|
return '[abbr=' + element.attr('title') + ']' + content + '[/abbr]'; |
262
|
|
|
}, |
263
|
|
|
html: function (element, attrs, content) { |
264
|
|
|
if (typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) |
265
|
|
|
return content; |
|
|
|
|
266
|
|
|
|
267
|
|
|
return '<abbr title="' + attrs.defaultattr + '">' + content + '</abbr>'; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
); |
271
|
|
|
|
272
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
273
|
|
|
'list', { |
274
|
|
|
breakStart: true, |
275
|
|
|
isInline: false, |
276
|
|
|
allowedChildren: ['*', 'li'], |
277
|
|
|
html: function (element, attrs, content) { |
278
|
|
|
var style = ''; |
279
|
|
|
var code = 'ul'; |
280
|
|
|
var olTypes = new Array('decimal', 'decimal-leading-zero', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha', 'lower-greek', 'upper-greek', 'lower-latin', 'upper-latin', 'hebrew', 'armenian', 'georgian', 'cjk-ideographic', 'hiragana', 'katakana', 'hiragana-iroha', 'katakana-iroha'); |
|
|
|
|
281
|
|
|
|
282
|
|
|
if (attrs.type) { |
283
|
|
|
style = ' style="list-style-type: ' + attrs.type + '"'; |
284
|
|
|
|
285
|
|
|
if (olTypes.indexOf(attrs.type) > -1) |
286
|
|
|
code = 'ol'; |
|
|
|
|
287
|
|
|
} |
288
|
|
|
else |
289
|
|
|
style = ' style="list-style-type: disc"'; |
|
|
|
|
290
|
|
|
|
291
|
|
|
return '<' + code + style + '>' + content + '</' + code + '>'; |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
); |
295
|
|
|
|
296
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
297
|
|
|
'ul', { |
298
|
|
|
tags: { |
299
|
|
|
ul: null |
300
|
|
|
}, |
301
|
|
|
breakStart: true, |
302
|
|
|
isInline: false, |
303
|
|
|
html: '<ul>{0}</ul>', |
304
|
|
|
format: function (element, content) { |
305
|
|
|
if ($(element[0]).css('list-style-type') == 'disc') |
306
|
|
|
return '[list]' + content + '[/list]'; |
|
|
|
|
307
|
|
|
else |
308
|
|
|
return '[list type=' + $(element[0]).css('list-style-type') + ']' + content + '[/list]'; |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
); |
312
|
|
|
|
313
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
314
|
|
|
'ol', { |
315
|
|
|
tags: { |
316
|
|
|
ol: null |
317
|
|
|
}, |
318
|
|
|
breakStart: true, |
319
|
|
|
isInline: false, |
320
|
|
|
html: '<ol>{0}</ol>', |
321
|
|
|
format: function (element, content) { |
322
|
|
|
if ($(element[0]).css('list-style-type') == 'none') |
323
|
|
|
return '[list type=decimal]' + content + '[/list]'; |
|
|
|
|
324
|
|
|
else |
325
|
|
|
return '[list type=' + $(element[0]).css('list-style-type') + ']' + content + '[/list]'; |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
); |
329
|
|
|
|
330
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
331
|
|
|
'img', { |
332
|
|
|
tags: { |
333
|
|
|
img: { |
334
|
|
|
src: null |
335
|
|
|
} |
336
|
|
|
}, |
337
|
|
|
allowsEmpty: true, |
338
|
|
|
quoteType: $.sceditor.BBCodeParser.QuoteType.never, |
339
|
|
|
format: function (element, content) { |
|
|
|
|
340
|
|
|
var attribs = '', |
341
|
|
|
style = function (name) { |
342
|
|
|
return element.style ? element.style[name] : null; |
343
|
|
|
}; |
344
|
|
|
|
345
|
|
|
// check if this is an emoticon image |
346
|
|
|
if (typeof element.attr('data-sceditor-emoticon') !== "undefined") |
347
|
|
|
return content; |
|
|
|
|
348
|
|
|
|
349
|
|
|
// only add width and height if one is specified |
350
|
|
|
if (element.attr('width') || style('width')) |
351
|
|
|
attribs += " width=" + $(element).width(); |
|
|
|
|
352
|
|
|
if (element.attr('height') || style('height')) |
353
|
|
|
attribs += " height=" + $(element).height(); |
|
|
|
|
354
|
|
|
if (element.attr('alt')) |
355
|
|
|
attribs += " alt=" + element.attr('alt'); |
|
|
|
|
356
|
|
|
|
357
|
|
|
// Is this an attachment? |
358
|
|
|
if (element.attr('data-attachment')) |
359
|
|
|
{ |
360
|
|
|
if (element.attr('title')) |
361
|
|
|
attribs += ' name=' + element.attr('title'); |
|
|
|
|
362
|
|
|
if (element.attr('data-type')) |
363
|
|
|
attribs += ' type=' + element.attr('data-type'); |
|
|
|
|
364
|
|
|
|
365
|
|
|
return '[attach' + attribs + ']' + element.attr('data-attachment') + '[/attach]'; |
366
|
|
|
} |
367
|
|
|
else if (element.attr('title')) |
368
|
|
|
attribs += " title=" + element.attr('title'); |
|
|
|
|
369
|
|
|
|
370
|
|
|
return '[img' + attribs + ']' + element.attr('src') + '[/img]'; |
371
|
|
|
}, |
372
|
|
|
html: function (token, attrs, content) { |
373
|
|
|
var parts, |
|
|
|
|
374
|
|
|
attribs = ''; |
375
|
|
|
|
376
|
|
|
// handle [img width=340 height=240]url[/img] |
377
|
|
|
if (typeof attrs.width !== "undefined") |
378
|
|
|
attribs += ' width="' + attrs.width + '"'; |
|
|
|
|
379
|
|
|
if (typeof attrs.height !== "undefined") |
380
|
|
|
attribs += ' height="' + attrs.height + '"'; |
|
|
|
|
381
|
|
|
if (typeof attrs.alt !== "undefined") |
382
|
|
|
attribs += ' alt="' + attrs.alt + '"'; |
|
|
|
|
383
|
|
|
if (typeof attrs.title !== "undefined") |
384
|
|
|
attribs += ' title="' + attrs.title + '"'; |
|
|
|
|
385
|
|
|
|
386
|
|
|
return '<img' + attribs + ' src="' + content + '">'; |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
); |
390
|
|
|
|
391
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
392
|
|
|
'attach', { |
393
|
|
|
tags: { |
394
|
|
|
attach: { |
395
|
|
|
src: null |
396
|
|
|
} |
397
|
|
|
}, |
398
|
|
|
allowsEmpty: true, |
399
|
|
|
quoteType: $.sceditor.BBCodeParser.QuoteType.never, |
400
|
|
|
format: function (element, content) { |
|
|
|
|
401
|
|
|
var attribs = '', |
402
|
|
|
style = function (name) { |
403
|
|
|
return element.style ? element.style[name] : null; |
404
|
|
|
}; |
405
|
|
|
|
406
|
|
|
// only add width and height if one is specified |
407
|
|
|
if (element.attr('width') || style('width')) |
408
|
|
|
attribs += " width=" + $(element).width(); |
|
|
|
|
409
|
|
|
if (element.attr('height') || style('height')) |
410
|
|
|
attribs += " height=" + $(element).height(); |
|
|
|
|
411
|
|
|
if (element.attr('alt')) |
412
|
|
|
attribs += " alt=" + element.attr('alt'); |
|
|
|
|
413
|
|
|
if (element.attr('title')) |
414
|
|
|
attribs += " name=" + element.attr('title'); |
|
|
|
|
415
|
|
|
if (element.attr('data-type')) |
416
|
|
|
attribs += " type=" + element.attr('data-type'); |
|
|
|
|
417
|
|
|
|
418
|
|
|
return '[attach' + attribs + ']' + (element.attr('data-attachment') ? element.attr('data-attachment') : content) + '[/attach]'; |
419
|
|
|
}, |
420
|
|
|
html: function (token, attrs, id) { |
421
|
|
|
var parts, |
|
|
|
|
422
|
|
|
attribs = ''; |
423
|
|
|
|
424
|
|
|
// If id is not an integer, bail out |
425
|
|
|
if (!$.isNumeric(id) || Math.floor(id) != +id || +id <= 0) { |
426
|
|
|
|
427
|
|
|
if (typeof attrs.width !== "undefined") |
428
|
|
|
attribs += ' width=' + attrs.width; |
|
|
|
|
429
|
|
|
if (typeof attrs.height !== "undefined") |
430
|
|
|
attribs += ' height=' + attrs.height; |
|
|
|
|
431
|
|
|
if (typeof attrs.alt !== "undefined") |
432
|
|
|
attribs += ' alt=' + attrs.alt; |
|
|
|
|
433
|
|
|
if (typeof attrs.name !== "undefined") |
434
|
|
|
attribs += ' name=' + attrs.name; |
|
|
|
|
435
|
|
|
if (typeof attrs.type !== "undefined") |
436
|
|
|
attribs += ' type=' + attrs.type; |
|
|
|
|
437
|
|
|
|
438
|
|
|
return '[attach' + attribs + ']' + id + '[/attach]'; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
attribs += ' data-attachment="' + id + '"' |
442
|
|
|
if (typeof attrs.width !== "undefined") |
443
|
|
|
attribs += ' width="' + attrs.width + '"'; |
|
|
|
|
444
|
|
|
if (typeof attrs.height !== "undefined") |
445
|
|
|
attribs += ' height="' + attrs.height + '"'; |
|
|
|
|
446
|
|
|
if (typeof attrs.alt !== "undefined") |
447
|
|
|
attribs += ' alt="' + attrs.alt + '"'; |
|
|
|
|
448
|
|
|
if (typeof attrs.type !== "undefined") |
449
|
|
|
attribs += ' data-type="' + attrs.type + '"'; |
|
|
|
|
450
|
|
|
if (typeof attrs.name !== "undefined") |
451
|
|
|
attribs += ' title="' + attrs.name + '"'; |
|
|
|
|
452
|
|
|
|
453
|
|
|
// Is this an image? |
454
|
|
|
if ((typeof attrs.type !== "undefined" && attrs.type.indexOf("image") === 0)) { |
455
|
|
|
var contentUrl = smf_scripturl +'?action=dlattach;attach='+ id + ';type=preview;thumb'; |
|
|
|
|
456
|
|
|
contentIMG = new Image(); |
|
|
|
|
457
|
|
|
contentIMG.src = contentUrl; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
// If not an image, show a boring ol' link |
461
|
|
|
if (typeof contentUrl === "undefined" || contentIMG.getAttribute('width') == 0) |
|
|
|
|
462
|
|
|
return '<a href="' + smf_scripturl + '?action=dlattach;attach=' + id + ';type=preview;file"' + attribs + '>' + (typeof attrs.name !== "undefined" ? attrs.name : id) + '</a>'; |
|
|
|
|
463
|
|
|
// Show our purdy li'l picture |
464
|
|
|
else |
465
|
|
|
return '<img' + attribs + ' src="' + contentUrl + '">'; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
); |
469
|
|
|
|
470
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
471
|
|
|
'url', { |
472
|
|
|
allowsEmpty: true, |
473
|
|
|
quoteType: $.sceditor.BBCodeParser.QuoteType.never, |
474
|
|
|
tags: { |
475
|
|
|
a: { |
476
|
|
|
href: null |
477
|
|
|
} |
478
|
|
|
}, |
479
|
|
|
format: function (element, content) { |
480
|
|
|
var url = element.attr('href'); |
481
|
|
|
|
482
|
|
|
// make sure this link is not an e-mail, if it is return e-mail BBCode |
483
|
|
|
if (url.substr(0, 7) === 'mailto:') |
484
|
|
|
return '[email=' + url.substr(7) + ']' + content + '[/email]'; |
|
|
|
|
485
|
|
|
|
486
|
|
|
if (typeof element.attr('target') !== "undefined") |
487
|
|
|
return '[url=\"' + decodeURI(url) + '\"]' + content + '[/url]'; |
|
|
|
|
488
|
|
|
|
489
|
|
|
// A mention? |
490
|
|
|
else if (typeof element.attr('data-mention') !== "undefined") |
491
|
|
|
{ |
492
|
|
|
return '[member='+ element.attr('data-mention') +']'+ content.replace('@','') +'[/member]'; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
// Is this an attachment? |
496
|
|
|
else if (typeof element.attr('data-attachment') !== "undefined") |
497
|
|
|
{ |
498
|
|
|
var attribs = ''; |
499
|
|
|
if (typeof element.attr('title') !== "undefined") |
500
|
|
|
attribs += ' name=' + element.attr('title'); |
|
|
|
|
501
|
|
|
if (typeof element.attr('data-type') !== "undefined") |
502
|
|
|
attribs += ' type=' + element.attr("data-type"); |
|
|
|
|
503
|
|
|
|
504
|
|
|
return '[attach' + attribs + ']' + element.attr('data-attachment') + '[/attach]'; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
else |
508
|
|
|
return '[iurl=\"' + decodeURI(url) + '\"]' + content + '[/iurl]'; |
|
|
|
|
509
|
|
|
}, |
510
|
|
|
html: function (token, attrs, content) { |
511
|
|
|
if (typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) |
512
|
|
|
attrs.defaultattr = content; |
|
|
|
|
513
|
|
|
|
514
|
|
|
return '<a target="_blank" href="' + encodeURI(attrs.defaultattr) + '">' + content + '</a>'; |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
); |
518
|
|
|
|
519
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
520
|
|
|
'iurl', { |
521
|
|
|
allowsEmpty: true, |
522
|
|
|
quoteType: $.sceditor.BBCodeParser.QuoteType.never, |
523
|
|
|
html: function (token, attrs, content) { |
524
|
|
|
|
525
|
|
|
if (typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) |
526
|
|
|
attrs.defaultattr = content; |
|
|
|
|
527
|
|
|
|
528
|
|
|
return '<a href="' + encodeURI(attrs.defaultattr) + '">' + content + '</a>'; |
529
|
|
|
} |
530
|
|
|
} |
531
|
|
|
); |
532
|
|
|
|
533
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
534
|
|
|
'pre', { |
535
|
|
|
tags: { |
536
|
|
|
pre: null |
537
|
|
|
}, |
538
|
|
|
isBlock: true, |
539
|
|
|
format: "[pre]{0}[/pre]", |
540
|
|
|
html: "<pre>{0}</pre>\n" |
541
|
|
|
} |
542
|
|
|
); |
543
|
|
|
|
544
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
545
|
|
|
'php', { |
546
|
|
|
isInline: false, |
547
|
|
|
format: "[php]{0}[/php]", |
548
|
|
|
html: '<code class="php">{0}</code>' |
549
|
|
|
} |
550
|
|
|
); |
551
|
|
|
|
552
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
553
|
|
|
'code', { |
554
|
|
|
tags: { |
555
|
|
|
code: null |
556
|
|
|
}, |
557
|
|
|
isInline: false, |
558
|
|
|
allowedChildren: ['#', '#newline'], |
559
|
|
|
format: function (element, content) { |
560
|
|
|
if ($(element[0]).hasClass('php')) |
561
|
|
|
return '[php]' + content.replace('[', '[') + '[/php]'; |
|
|
|
|
562
|
|
|
|
563
|
|
|
var from = ''; |
564
|
|
|
if ($(element).children("cite:first").length === 1) |
565
|
|
|
{ |
566
|
|
|
from = $(element).children("cite:first").text(); |
567
|
|
|
|
568
|
|
|
$(element).attr({'from': from.php_htmlspecialchars()}); |
569
|
|
|
|
570
|
|
|
from = '=' + from; |
571
|
|
|
content = ''; |
|
|
|
|
572
|
|
|
$(element).children("cite:first").remove(); |
573
|
|
|
content = this.elementToBbcode($(element)); |
574
|
|
|
} |
575
|
|
|
else |
576
|
|
|
{ |
577
|
|
|
if (typeof $(element).attr('from') != 'undefined') |
578
|
|
|
{ |
579
|
|
|
from = '=' + $(element).attr('from').php_unhtmlspecialchars(); |
580
|
|
|
} |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
return '[code' + from + ']' + content.replace('[', '[') + '[/code]'; |
584
|
|
|
|
585
|
|
|
}, |
586
|
|
|
html: function (element, attrs, content) { |
587
|
|
|
var from = ''; |
588
|
|
|
if (typeof attrs.defaultattr !== "undefined") |
589
|
|
|
from = '<cite>' + attrs.defaultattr + '</cite>'; |
|
|
|
|
590
|
|
|
|
591
|
|
|
return '<code>' + from + content.replace('[', '[') + '</code>' |
592
|
|
|
} |
593
|
|
|
} |
594
|
|
|
); |
595
|
|
|
|
596
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
597
|
|
|
'quote', { |
598
|
|
|
tags: { |
599
|
|
|
blockquote: null, |
600
|
|
|
cite: null |
601
|
|
|
}, |
602
|
|
|
quoteType: $.sceditor.BBCodeParser.QuoteType.never, |
603
|
|
|
breakBefore: false, |
604
|
|
|
isInline: false, |
605
|
|
|
format: function (element, content) { |
606
|
|
|
var author = ''; |
607
|
|
|
var date = ''; |
608
|
|
|
var link = ''; |
609
|
|
|
|
610
|
|
|
// The <cite> contains only the graphic for the quote, so we can skip it |
611
|
|
|
if (element[0].tagName.toLowerCase() === 'cite') |
612
|
|
|
return ''; |
|
|
|
|
613
|
|
|
|
614
|
|
|
if (element.attr('author')) |
615
|
|
|
author = ' author=' + element.attr('author').php_unhtmlspecialchars(); |
|
|
|
|
616
|
|
|
if (element.attr('link')) |
617
|
|
|
link = ' link=' + element.attr('link'); |
|
|
|
|
618
|
|
|
if (element.attr('date')) |
619
|
|
|
date = ' date=' + element.attr('date'); |
|
|
|
|
620
|
|
|
|
621
|
|
|
return '[quote' + author + link + date + ']' + content + '[/quote]'; |
622
|
|
|
}, |
623
|
|
|
html: function (element, attrs, content) { |
624
|
|
|
var attr_author = '', author = ''; |
625
|
|
|
var attr_date = '', sDate = ''; |
626
|
|
|
var attr_link = '', link = ''; |
627
|
|
|
|
628
|
|
|
if (typeof attrs.author !== "undefined" && attrs.author) |
629
|
|
|
{ |
630
|
|
|
attr_author = attrs.author; |
631
|
|
|
author = bbc_quote_from + ': ' + attr_author; |
|
|
|
|
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
// Links could be in the form: link=topic=71.msg201#msg201 that would fool javascript, so we need a workaround |
635
|
|
|
// Probably no more necessary |
636
|
|
|
for (var key in attrs) |
|
|
|
|
637
|
|
|
{ |
638
|
|
|
if (key.substr(0, 4) == 'link' && attrs.hasOwnProperty(key)) |
639
|
|
|
{ |
640
|
|
|
var attr_link = key.length > 4 ? key.substr(5) + '=' + attrs[key] : attrs[key]; |
|
|
|
|
641
|
|
|
|
642
|
|
|
link = attr_link.substr(0, 7) == 'http://' ? attr_link : smf_scripturl + '?' + attr_link; |
|
|
|
|
643
|
|
|
author = author == '' ? '<a href="' + link + '">' + bbc_quote_from + ': ' + link + '</a>' : '<a href="' + link + '">' + author + '</a>'; |
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
if (typeof attrs.date !== "undefined" && attrs.date) |
648
|
|
|
{ |
649
|
|
|
attr_date = attrs.date; |
650
|
|
|
sDate = '<date timestamp="' + attr_date + '">' + new Date(attrs.date * 1000) + '</date>'; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
if (author == '' && sDate == '') |
654
|
|
|
author = bbc_quote; |
|
|
|
|
655
|
|
|
else if (author == '' && sDate != '') |
656
|
|
|
author += ' ' + bbc_search_on; |
|
|
|
|
657
|
|
|
|
658
|
|
|
content = '<blockquote author="' + attr_author + '" date="' + attr_date + '" link="' + attr_link + '"><cite>' + author + ' ' + sDate + '</cite>' + content + '</blockquote>'; |
659
|
|
|
|
660
|
|
|
return content; |
661
|
|
|
} |
662
|
|
|
} |
663
|
|
|
); |
664
|
|
|
|
665
|
|
|
$.sceditor.plugins.bbcode.bbcode.set('font', { |
666
|
|
|
format: function ($element, content) { |
667
|
|
|
var font; |
668
|
|
|
|
669
|
|
|
// Get the raw font value from the DOM |
670
|
|
|
if (!$element.is('font') || !(font = $element.attr('face'))) { |
671
|
|
|
font = $element.css('font-family'); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
// Strip all quotes |
675
|
|
|
font = font.replace(/['"]/g, ''); |
676
|
|
|
|
677
|
|
|
return '[font=' + font + ']' + content + '[/font]'; |
678
|
|
|
} |
679
|
|
|
}); |
680
|
|
|
|
681
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
682
|
|
|
'member', { |
683
|
|
|
isInline: true, |
684
|
|
|
format: function ($element, content) { |
685
|
|
|
return '[member='+ $element.attr('data-mention') +']'+ content.replace('@','') +'[/member]'; |
686
|
|
|
}, |
687
|
|
|
html: function (token, attrs, content) { |
688
|
|
|
if (typeof attrs.defaultattr === "undefined" || attrs.defaultattr.length === 0) |
689
|
|
|
attrs.defaultattr = content; |
|
|
|
|
690
|
|
|
|
691
|
|
|
return '<a href="' + smf_scripturl +'?action=profile;u='+ attrs.defaultattr + '" class="mention" data-mention="'+ attrs.defaultattr + '">@'+ content.replace('@','') +'</a>'; |
|
|
|
|
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
); |
695
|
|
|
|
696
|
|
|
$.sceditor.plugins.bbcode.bbcode.set( |
697
|
|
|
'float', { |
698
|
|
|
tags: { |
699
|
|
|
div: { |
700
|
|
|
"class": ["floatleft", "floatright"], |
701
|
|
|
}, |
702
|
|
|
}, |
703
|
|
|
isInline: false, |
704
|
|
|
skipLastLineBreak: true, |
705
|
|
|
format: function ($element, content) { |
706
|
|
|
if (!$element.css('float')) |
707
|
|
|
return content; |
|
|
|
|
708
|
|
|
|
709
|
|
|
side = ($element.css('float').indexOf('left') == 0 ? 'left' : 'right'); |
|
|
|
|
710
|
|
|
max = ' max=' + ($element.css('max-width') != "none" ? $element.css('max-width') : '45%'); |
|
|
|
|
711
|
|
|
|
712
|
|
|
return '[float=' + side + max + ']' + content + '[/float]'; |
713
|
|
|
}, |
714
|
|
|
html: function (token, attrs, content) { |
715
|
|
|
if (typeof attrs.defaultattr === "undefined") |
716
|
|
|
return content; |
|
|
|
|
717
|
|
|
|
718
|
|
|
floatclass = attrs.defaultattr.indexOf('left') == 0 ? 'floatleft' : 'floatright'; |
|
|
|
|
719
|
|
|
style = typeof attrs.max !== "undefined" ? ' style="max-width:' + attrs.max + (+attrs.max === parseInt(attrs.max) ? 'px' : '') + ';"' : ''; |
|
|
|
|
720
|
|
|
|
721
|
|
|
return '<div class="' + floatclass + '"' + style + '>' + content + '</div>'; |
722
|
|
|
} |
723
|
|
|
} |
724
|
|
|
); |
725
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.